import random
from Config.RunConfig import RunConfig, Options


class JobOperations:
    def __init__(self):
        self._operationsList = [
            self._enumerateJobs,
            self._enumerateJobTypeDescriptors,
        ]
        if  RunConfig().get(Options.StressTest.stressAllPartners) == 'True':
             self._operationsList.append(self._addRootJob)
             self._operationsList.append(self._controlJob)

        self._jobType = [
            'ConsolidateStorageNodeData',
            'ConsolidateAccountData',
            'DeleteAccount',
            'CopyAccountData',
            'DeleteAccountData',
            'ControlAccountData',
            'CheckCabinetConsistency',
            'RelocateAccountNode',
            'ControlAccountNode',
            'ChangeStorageNodeCredentials',
            'ChangeCredentialsOnStorageNode',
            'ChangeCredentialsInDatabase',
            'UninstallAccount',
            'SendAccountCommand',
            'MoveAccountData',
        ]
        self._jobControlAction = [
            'Approve',
            'Cancel',
            'Restart',
            'Finalize',
        ]

    def _getRandomOperation(self):
        return random.choice(self._operationsList)

    def _addRootJob(self, manserv, partnerId):
        manserv.AddRootJob(partnerId = partnerId, type = random.choice(self._jobType),
                           startAtTime = '2034-04-17T16:50:45', executorId = random.randint(0, 10))

    def _enumerateJobs(self, manserv, partnerId):
        manserv.EnumerateJobs(partnerId = partnerId)

    def _enumerateJobTypeDescriptors(self, manserv, partnerId):
        manserv.EnumerateJobTypeDescriptors()

    def _controlJob(self, manserv, partnerId):
        manserv.ControlJob(jobId = random.randint(0, 100), action = random.choice(self._jobControlAction))
